package com.yongcheon.starhealthcare.friend;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuItem;

import com.yongcheon.starhealthcare.R;
import com.yongcheon.starhealthcare.friend.fragment.Friend_FragementListener;
import com.yongcheon.starhealthcare.friend.fragment.Friend_FragmentPagerAdapter;

public class FriendActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        setContentView(R.layout.friend_activity);
        setCutsomActionBar();
        setCustomFragment();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_friend, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void setCutsomActionBar(){
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        getActionBar().setHomeButtonEnabled(false);
        getActionBar().setDisplayHomeAsUpEnabled(false);
    }

    private void setCustomFragment(){
        Friend_FragmentPagerAdapter friend_fragmentPagerAdapter = new Friend_FragmentPagerAdapter(getApplicationContext(), getSupportFragmentManager());

        ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(friend_fragmentPagerAdapter);

        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                getActionBar().setSelectedNavigationItem(position);
            }
        });

        Friend_FragementListener friend_fragementListener = new Friend_FragementListener(mViewPager);
        for (int i = 0; i < friend_fragmentPagerAdapter.getCount(); i++) {
            getActionBar().addTab(getActionBar().newTab()
                    .setText(friend_fragmentPagerAdapter.getPageTitle(i))
                    .setTabListener(friend_fragementListener));
        }
    }
}
